package com.zwr.mvpdemo.net;

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by zwr on 2017/5/3.
 */

public enum RetrofitClient {


    BASE("http://sxapp.shengxunsoft.com/IsxApp.asmx/"),
    DYNAMIC("http://ws.shengxunsoft.com/sxapp/");
    private final Retrofit retrofit;

    RetrofitClient(String baseUrl) {

        retrofit = new Retrofit.Builder()
                //设置OKHttpClient
                .client(OKHttpFactory.INSTANCE.getOkHttpClient())
                //baseUrl
                .baseUrl(baseUrl)
                //gson转化器
                .addConverterFactory(GsonConverterFactory.create())
                //.addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();

    }


    /**
     * 获取单例 retrofit对象
     * @return
     */
    public Retrofit getRetrofit() {
        return retrofit;
    }

    /**
     * 创建APIService
     *    public <T> T createReq(Class<T> reqServer){
     *
     *             return mRetrofit.create(reqServer);
     *       }
     */
    private APIService apiService = null;


    public APIService createApi() {
        if(null == apiService){
            apiService = retrofit.create(APIService.class);
        }
        return  apiService;
    }




}

